package com.example.shixunandjavagotoyangchen.BoosYang.Day001;

import android.util.Log;
import android.view.View;
import android.widget.Button;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import com.blankj.utilcode.util.ToastUtils;
import com.example.modelviewpresenter.View.BasterFragment;
import com.example.shixunandjavagotoyangchen.BoosYang.Day001.Day00102.SmileDay00102Adpter;
import com.example.shixunandjavagotoyangchen.BoosYang.Day001.Day00102.SmileDay00102Bean;
import com.example.shixunandjavagotoyangchen.BoosYang.Day001.Day00102.SmileDay00102Contion;
import com.example.shixunandjavagotoyangchen.BoosYang.Day001.Day00102.SmileDay00102Model;
import com.example.shixunandjavagotoyangchen.BoosYang.Day001.Day00102.SmileDay00102Presenter;
import com.example.shixunandjavagotoyangchen.BoosYang.Day001.Day00107.BaseDay00107Adpter;
import com.example.shixunandjavagotoyangchen.BoosYang.Day001.Day00107.BaseDay00107Bean;
import com.example.shixunandjavagotoyangchen.BoosYang.Day002.BlankFragmentDay002;
import com.example.shixunandjavagotoyangchen.R;
import com.scwang.smart.refresh.layout.SmartRefreshLayout;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.listener.OnRefreshLoadMoreListener;

import java.util.List;

import q.rorbin.verticaltablayout.VerticalTabLayout;
import q.rorbin.verticaltablayout.widget.TabView;


public class BlankFragmentDay00102 extends BasterFragment implements OnRefreshLoadMoreListener , SmileDay00102Contion.vier {

    public SmileDay00102Presenter presenter;
    public int smilesum = 0;
    public int smilepage =10;
    public boolean issmile = true;
    private RecyclerView SmileRecyclerView;
    public static SmartRefreshLayout SmileSmartRefreshLayout;
    public SmileDay00102Adpter adpter;



    @Override
    public int BandLayout() {
        return R.layout.fragment_blank_fragment_day00102;
    }

    @Override
    public void initView() {

        SmileRecyclerView = (RecyclerView) findViewById(R.id.Smile_RecyclerView);
        SmileRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
        SmileSmartRefreshLayout = (SmartRefreshLayout) findViewById(R.id.Smile_SmartRefreshLayout);
        SmileSmartRefreshLayout.setOnRefreshLoadMoreListener(this);

        presenter = new SmileDay00102Presenter(this,new SmileDay00102Model());
        presenter.simlering("/video/findVideos?currentPage="+smilepage+"&pageSize=10");
    }

    @Override
    public void initDate() {




    }

    @Override
    public void getvier(List<SmileDay00102Bean.DataBean> dataBeans) {
        for (SmileDay00102Bean.DataBean dataBean : dataBeans) {
            dataBean.setSmiletatyLayout(++smilesum);
            if (smilesum==4){
                smilesum=0;
            }
        }
        SmileSmartRefreshLayout.finishLoadMore();
        SmileSmartRefreshLayout.finishRefresh();
        if (adpter==null){
            adpter = new SmileDay00102Adpter(dataBeans);
            SmileRecyclerView.setAdapter(adpter);
        }else {
            if (issmile){
                adpter.getData().clear();
            }
            adpter.getData().addAll(dataBeans);
            adpter.notifyDataSetChanged();
        }
    }



    @Override
    public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
        issmile=false;
        smilepage++;
        presenter.simlering("/video/findVideos?currentPage="+smilepage+"&pageSize=10");
        Log.i("BlankFragmentDay001","----02加载:"+smilepage);
    }

    @Override
    public void onRefresh(@NonNull RefreshLayout refreshLayout) {

        if (issmile){
            smilepage=10;
        }
        presenter.simlering("/video/findVideos?currentPage="+smilepage+"&pageSize=10");
        Log.i("BlankFragmentDay001","---02刷新:"+smilepage);
    }


}
